public class MaxProfit {

    public int solution(int[] prices) {
        int res=0;
        for (int i = 0; i < prices.length-1; i++) {
            int a=Math.max(prices[i+1]-prices[i],0);
            res+=a;
        }
        return res;
    }


    public static int answer(int[] prices){
        int res=0;
        for (int i = 0; i < prices.length-1; i++) {
            for (int j = i+1; j < prices.length; j++) {
                res=Math.max(prices[j]-prices[i],res);
            }
        }
        return res;
    }

    public static int answer2(int[] prices){
        int minValue = Integer.MAX_VALUE;
        int res=0;
        for (int i = 0; i < prices.length; i++) {
            if(prices[i]<minValue){
                minValue=prices[i];
            }else if (prices[i]-minValue>res){
                res=prices[i]-minValue;
            }
        }
        return res;
    }

    public static int answer3(int[] prices){
       int res=0;
        for (int i = 0; i < prices.length-1; i++) {
            res+=Math.max(prices[i+1]-prices[i],0);
        }
        return res;
    }




    public static void main(String[] args) {
        int[] nums=new int[]{1,2,3,4,5};
        System.out.println(answer3(nums));
    }
}
